#!/usr/bin/perl -wc

package RFCMail::Util::FileDump;

# Frequently required functions to dump data out to a file.

use strict;
use base qw(Exporter);
use IO::File;
use Data::Dumper;

our @EXPORT = qw(
		 dump_to_file
		 dump_to_file_as_lines
		 dump_data_to_file
		);


sub dump_to_file {
    my $filename = shift;
    my $file = IO::File->new($filename, ">")
	or die "can't open '$filename' for writing: $!\n";
    if (@_) {
	$file->print(@_)
	    or die "can't write to '$filename': $!\n";
    }
    $file->close()
	or die "can't close '$filename': $!\n";
    return (1);
}


sub dump_to_file_as_lines {
    local $, = "\n";
    local $\ = "\n";
    &dump_to_file;
}


sub dump_data_to_file {
    my ($filename, @data) = @_;
    local $Data::Dumper::Terse = 1;
    local $Data::Dumper::Indent = 1;
    for (@data) {
	$_ = Dumper($_);
	chomp;
    }
    local $, = ",\n";
    local $\ = "\n";
    return (dump_to_file($filename, @data));
}


1;
